package com.chenyi.algorithm.sort;

import java.util.Arrays;

/**
 * @author by chenyi
 * @className BubbleSorting
 * @date 2022/1/26 16:16
 */

public class BubbleSorting {

    public static void main(String[] args) {
        int[] arr = {-1, 9, 2, 13, -2};
        sort(arr);

        System.out.println("排序后的数组" + Arrays.toString(arr));
    }


    public static void sort(int[] arr) {
        int num = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    num = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = num;
                }
            }
        }
    }

}
